`include "../include/common.sv"
module CorrectFlitere #(
	parameter BUFFER_DEPTH = 6
)(
	input logic cpu_clk,
	input logic cpu_rst_n,
	input logic [BUFFER_DEPTH-1: 0] search_index,
	input logic [6: 0] search_tag,
	input logic we,
	input logic [BUFFER_DEPTH-1: 0] write_index,
	input logic [6 :0] write_tag,
	output logic revert
);
	logic [12: 0] douta, doutb, dina;
	logic [5: 0] din_ctr;
	SDPRAM #(
		.WORD_WIDTH(13),
		.DEPTH(`LSHIFTX(BUFFER_DEPTH)),
		.ADDR_WIDTH(BUFFER_DEPTH)
	) correct_buffer(
		.clk(cpu_clk),
		.ena(we),
		.addra(write_index),
		.wea(we),
		.dina(dina),
		.douta(douta),
		.enb(1'b1),
		.addrb(search_index),
		.doutb(doutb)
	);
	assign din_ctr = douta[6: 0] != write_tag ? 0 : douta[12: 7] == 6'b11111 ? douta[12: 7] : douta[12: 7] + 1;
	assign dina = {din_ctr, write_tag};
	assign revert = doutb[12] | doutb[11] | doutb[10];
endmodule